//
//  AddressTableViewCell.m
//  BeautyPicture
//
//  Created by 沈振邦 on 15/8/12.
//  Copyright (c) 2015年 szb. All rights reserved.
//

#import "AddressTableViewCell.h"

@implementation AddressTableViewCell
@synthesize delegate;

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"status";
    AddressTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[AddressTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self initLayuot];
    }
    return self;
}

-(void)initLayuot{

    //1.姓名
    CGFloat nameX = 17.0f + 15.0f;
    //CGFloat nameY = nameX + 2;
    //CGFloat nameW = 100.0f;
    CGFloat nameH = 20.0f;
#if 0
    _goodsName = [[UILabel alloc] initWithFrame:CGRectMake(nameX, nameY, nameW, nameH)];
    _goodsName.font = [UIFont systemFontOfSize:18.0f];
    [self addSubview:_goodsName];
    
    //2.联系电话
    CGFloat phoneX =CGRectGetMaxX(self.goodsName.frame);
    CGFloat phoneY = nameY;
    CGFloat phoneH = nameH;
    CGFloat phoneW = 150.0f;
    _goodsPhone = [[UILabel alloc] initWithFrame:CGRectMake(phoneX, phoneY, phoneW, phoneH)];
    _goodsPhone.font = [UIFont systemFontOfSize:18.0f];
    [self addSubview:_goodsPhone];
#endif
    //3.收货详情
    CGFloat textX = nameX;
   // CGFloat textY = CGRectGetMaxY(self.goodsName.frame) + 10.0f;
    CGFloat textY = 10;
    CGFloat textW = BPScreenW - 2 * textX;
    CGFloat textH = 40.0f;
    _goodsAddress = [[UILabel alloc] initWithFrame:CGRectMake(textX, textY, textW, textH)];
    _goodsAddress.font = [UIFont systemFontOfSize:14.0f];
    _goodsAddress.numberOfLines = 0;
    [self addSubview:_goodsAddress];

    //4.收货时间
    CGFloat timeX = nameX;
    CGFloat timeY = CGRectGetMaxY(self.goodsAddress.frame);
//    CGFloat timeY = 0;
    CGFloat timeW = 200.0;
    CGFloat timeH = nameH;
    _goodsTime = [[UILabel alloc] initWithFrame:CGRectMake(timeX, timeY, timeW, timeH)];
    _goodsTime.font = [UIFont systemFontOfSize:18.0f];
    [self addSubview:_goodsTime];
    
    // 空心圆点
    CGFloat KongX = nameX - 15.0f;
    CGFloat KongY = 21;
    CGFloat KongW = 12.0f;
    CGFloat KongH = 12.0f;
    
    
//    self.Kong = [[UIView alloc] initWithFrame:CGRectMake(KongX, KongY, KongW, KongH)];
//    self.Kong.layer.cornerRadius = 6.0f;
//    self.Kong.layer.masksToBounds = YES;
//    [self.Kong setBackgroundColor:[UIColor blackColor]];
//    [self addSubview:self.Kong];
    
//    self.Shi = [[UIView alloc] initWithFrame:CGRectMake(KongX+3, KongY+3, KongW-6, KongH-6)];
//    [self.Shi setBackgroundColor:[UIColor whiteColor]];
//    self.Shi.hidden = YES;
//    self.Shi.layer.cornerRadius = 3;
//    self.Shi.layer.masksToBounds = YES;
//    [self addSubview:self.Shi];
    
    self.yesS = [[UIButton alloc] initWithFrame:CGRectMake(KongX, KongY, KongW, KongH)];
    [self.yesS setImage:[UIImage imageNamed:@"iconfont-gouxuan-2"] forState:UIControlStateNormal];
    self.yesS.hidden = YES;
    [self addSubview:self.yesS];
    
    
//    CGFloat btnY = CGRectGetMaxY(_goodsTime.frame) + 5.0;
    CGFloat btnW = 15.0f;
    CGFloat btnH = 15.0f;
    CGFloat btnX = BPScreenW - nameX - btnW;
    _editButton = [UIButton buttonWithType: UIButtonTypeCustom];
    _editButton.frame = CGRectMake(btnX - btnW + 40.0f, 18, btnW, btnH);
    [_editButton setBackgroundImage:[UIImage imageNamed:@"edit"] forState:UIControlStateNormal];
//    [self setupButton:_editButton setupTitle:@"编辑" setupBgBtnColor:BPGlobaThemeColor];
    [_editButton addTarget:self action:@selector(editInfo:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_editButton];
    
//    _choAdd = [UIButton buttonWithType: UIButtonTypeCustom];
//    _choAdd.frame = CGRectMake(_editButton.x - btnW - 15.0f, btnY, btnW, btnH);
//    [self setupButton:_choAdd setupTitle:@"选择" setupBgBtnColor:BPGlobaThemeColor];
//    _choAdd.userInteractionEnabled = NO;
//    
//    _deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    _deleteBtn.frame = CGRectMake(btnX, btnY, btnW, btnH);
//    [self setupButton:_deleteBtn setupTitle:@"删除" setupBgBtnColor:pinkBtnColor];
//    [_deleteBtn addTarget:self action:@selector(removeCell:) forControlEvents:UIControlEventTouchUpInside];
    
//    CGFloat maxY = CGRectGetMaxY(_goodsTime.frame);
//    BPLineView *line = [[BPLineView alloc] initWithFrame:CGRectMake(0, maxY + 8.0, BPScreenW, 0.7)];
//    [self addSubview:line];
}

- (void)setupButton:(UIButton *)btn setupTitle:(NSString *)title setupBgBtnColor:(UIColor *)color
{
    [btn.layer setMasksToBounds:YES];
    [btn.layer setCornerRadius:14.0f];
    [btn setBackgroundColor:color];
    [btn setTitle:title forState:UIControlStateNormal];
    [self addSubview:btn];
}

- (void)setUpCellData:(BPAddressModel *)addressModel
{
    self.goodsName.text = addressModel.realname;
    self.goodsPhone.text = addressModel.phone;
    self.goodsAddress.text = [NSString stringWithFormat:@"%@ %@ %@ %@",addressModel.province,addressModel.city,addressModel.area,addressModel.address];
    self.goodsTime.text = addressModel.time;
}

- (void)removeCell:(UIButton *)sender
{
    if (delegate !=nil && [delegate respondsToSelector:@selector(DeleteCell:)]) {
        [self.delegate DeleteCell:self];
    }
}

- (void)editInfo:(UIButton *)sender
{
    if (delegate !=nil && [delegate respondsToSelector:@selector(editAddress:)]) {
        [self.delegate editAddress:self];
    }
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
